import { NDescriptions } from "naive-ui";
import type { DescriptionsProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type DescriptionsFactoryConstructorType = {
    props?: DescriptionsProps;
    attrs?: HTMLAttributes;
    defaultSlot?: BaseComponentType;
    headerSlot?: BaseComponentType;
}
export class DescriptionsFactory {
  private props: DescriptionsProps = {};
  private attrs: HTMLAttributes = {};
  private defaultSlot: BaseComponentType = null;
  private headerSlot: BaseComponentType = null;

  constructor(data?: DescriptionsFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
    if (data?.headerSlot) this.setHeader(data.headerSlot);
  }

  setProps(props: DescriptionsProps) {
    this.props = props;
    return this;
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }
  setHeader(component: BaseComponentType) {
    this.headerSlot = component;
    return this;
  }

  create() {
    return (
      <NDescriptions {...this.attrs} {...this.props}>
        {{
          default:()=> getSlotsDom(this.defaultSlot),
          header:()=> getSlotsDom(this.headerSlot),
        }}
      </NDescriptions>
    );
  }
}
